#include "Game.h"

Game::Game()
{
}

const QString& Game::name() const
{
    return m_name;
}

 void Game::setName(const QString &name)
{
    m_name = name;
}

const QString& Game::smallLogoUrl() const
{
    return m_smallLogoUrl;
}

void Game::setSmallLogoUrl(const QString &sLogoUrl)
{
    m_smallLogoUrl = sLogoUrl;
}

const QString& Game::storeUrl() const
{
    return m_storeUrl;
}

void Game::setStoreUrl(const QString &storeUrl)
{
    m_storeUrl = storeUrl;
}

const QString& Game::iconUrl() const
{
    return m_iconUrl;
}

void Game::setIconUrl(const QString &iconUrl)
{
    m_iconUrl = iconUrl;
}

const QString& Game::logoUrl() const
{
    return m_logoUrl;
}

void Game::setLogoUrl(const QString &logoUrl)
{
    m_logoUrl = logoUrl;
}

const QMap<QString, Achievement>& Game::achievements() const
{
    return m_achievementMap;
}

void Game::addAchievement(const Achievement &achievement)
{
    m_achievementMap.insert(achievement.name(), achievement);
}

void Game::addAchievement(QMap<QString, Achievement>achievementMap)
{
    /// not using QMap::unite because I don't want dups
    QMapIterator<QString, Achievement> i(achievementMap);
    while (i.hasNext())
    {
        i.next();
        m_achievementMap.insert(i.key(), i.value());
    }

}

void Game::setStatsUrl(const QString &statsUrl)
{
    m_statsUrl = statsUrl + "?tab=achievements&xml=1";
}

const QString& Game::statsUrl() const
{
    return m_statsUrl;
}

void Game::clearAchievements()
{
    m_achievementMap.clear();
}


QDataStream &operator<<(QDataStream &out, const Game &game)
{
    out << game.name() << game.storeUrl() << game.iconUrl()
            << game.logoUrl() << game.smallLogoUrl() << game.statsUrl()
            << game.achievements();
    return out;
}

QDataStream &operator>>(QDataStream &in, Game &game)
{
    QString name;
    QString storeUrl;
    QString iconUrl;
    QString logoUrl;
    QString sLogoUrl;
    QString statsUrl;
    QMap<QString, Achievement> achievementMap;

    in >> name >> storeUrl >> iconUrl >> logoUrl >> sLogoUrl
            >> statsUrl >> achievementMap;

    game.setName(name);
    game.setStoreUrl(storeUrl);
    game.setIconUrl(iconUrl);
    game.setLogoUrl(logoUrl);
    game.setSmallLogoUrl(sLogoUrl);
    game.setStatsUrl(statsUrl);
    game.addAchievement(achievementMap);
    return in;


}
